package com.ohuang.fakescreen.window

import android.app.Activity
import android.content.pm.ActivityInfo
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.TextView
import com.ohuang.fakescreen.R
import com.ohuang.fakescreen.SmallWindowView
import com.ohuang.fakescreen.dp2px
import com.ohuang.fakescreen.setTouchNoMoveClickListener
import com.ohuang.fakescreen.toColor

class OrientationSmallWindow(activity: Activity):SmallWindow(activity) {
    override fun createSmallView(): View {
        val windowView = LayoutInflater.from(activity).inflate(R.layout.small_change_orientation, null) as SmallWindowView
        windowView.wm=smallWindowsHelper.mWindowManager
        windowView.setWmParams(smallWindowsHelper.mLayoutParams)
        var tv_1 = windowView.findViewById<TextView>(R.id.tv_1)
        var tv_2 = windowView.findViewById<TextView>(R.id.tv_2)
        var tv_3 = windowView.findViewById<TextView>(R.id.tv_3)
        var tv_4 = windowView.findViewById<TextView>(R.id.tv_4)
        tv_1.setTextColor(0xffff0000.toColor())
        tv_1.setTouchNoMoveClickListener() {
            val mLayoutParams = smallWindowsHelper.mLayoutParams
            mLayoutParams?.screenOrientation= ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
            smallWindowsHelper.mLayoutParams = mLayoutParams
            tv_1.setTextColor(0xffff0000.toColor())
            tv_2.setTextColor(0xffffffff.toColor())
            tv_3.setTextColor(0xffffffff.toColor())

        }
        tv_2.setTouchNoMoveClickListener {
            val mLayoutParams = smallWindowsHelper.mLayoutParams
            mLayoutParams?.screenOrientation= ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
            smallWindowsHelper.mLayoutParams = mLayoutParams
            tv_2.setTextColor(0xffff0000.toColor())
            tv_1.setTextColor(0xffffffff.toColor())
            tv_3.setTextColor(0xffffffff.toColor())
        }
        tv_3.setTouchNoMoveClickListener {
            val mLayoutParams = smallWindowsHelper.mLayoutParams
            mLayoutParams?.screenOrientation= ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
            smallWindowsHelper.mLayoutParams = mLayoutParams
            tv_3.setTextColor(0xffff0000.toColor())
            tv_2.setTextColor(0xffffffff.toColor())
            tv_1.setTextColor(0xffffffff.toColor())
        }
        tv_4.setTouchNoMoveClickListener{
            if (tv_4.text=="收起"){
                tv_1.visibility=View.GONE
                tv_2.visibility=View.GONE
                tv_3.visibility=View.GONE
                tv_4.text="展开"
            }else{
                tv_1.visibility=View.VISIBLE
                tv_2.visibility=View.VISIBLE
                tv_3.visibility=View.VISIBLE
                tv_4.text="收起"
            }
        }

        return windowView
    }

    override fun initLayoutParam(layoutParams: WindowManager.LayoutParams): WindowManager.LayoutParams {
        layoutParams.width=100.dp2px(activity)
        layoutParams.screenOrientation=ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
        return layoutParams
    }

}